﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RestSharp;
using WeiTalk.SinaEntities.Search;
using WeiTalk.OAuth;

namespace WeiTalk.Interfaces.Sina
{
    public class SearchAPI : WeiBoAPIs
    {
        public SearchAPI(RestClient client) : base(client) { }
        const string AtUsersUrl = "https://api.weibo.com/2/search/suggestions/at_users.json";

        /// <summary>
        /// @用户时的联想建议
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="q">搜索的关键字，必须做URLencoding。</param>
        /// <param name="count">返回的记录条数，默认为10，粉丝最多1000，关注最多2000。</param>
        /// <param name="type">联想类型，0：关注、1：粉丝。</param>
        /// <param name="range">联想范围，0：只联想关注人、1：只联想关注人的备注、2：全部，默认为2。</param>
        public void GetAtUser(Action<IRestResponse<AtUsers>> callback, string q, int count = 10, int type = 0, int range = 2)
        {
            RestRequest request = new RestRequest(AtUsersUrl, Method.GET);
            request.AddParameter("source", Utility.ConsumerKey);
            request.AddParameter("access_token", Utility.AccessToken.Token);
            request.AddParameter("count", count);
            request.AddParameter("type", type);
            request.AddParameter("range", range);
            request.AddParameter("q", q);
            request.AddParameter("type", "json");
            request.AddParameter("timestamp", Guid.NewGuid().ToString());
            Client.ExecuteAsync<AtUsers>(request, callback);
        }
    }
}
